<template>
  <div class="mod-crm__crmperson">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.id" placeholder="" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.name" placeholder="姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.company" placeholder="公司" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.mobile" placeholder="手机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.address" placeholder="地址" clearable></el-input>
      </el-form-item>
      <el-form-item>
            <el-radio-group v-model="state.dataForm.category">
              <el-radio :label="0">单选</el-radio>
            </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.source" placeholder="来源" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.state" placeholder="状态" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmperson:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmperson:delete')" type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="id" label="" header-align="center" align="center"></el-table-column>
      <el-table-column prop="name" label="姓名" header-align="center" align="center"></el-table-column>
      <el-table-column prop="firstName" label="英文名" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lastName" label="英文姓" header-align="center" align="center"></el-table-column>
      <el-table-column prop="gender" label="性别" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("gender", scope.row.gender) }}
        </template>
      </el-table-column>
      <el-table-column prop="company" label="公司" header-align="center" align="center"></el-table-column>
      <el-table-column prop="mobile" label="手机号" header-align="center" align="center" width="150"></el-table-column>
      <el-table-column prop="department" label="部门" header-align="center" align="center"></el-table-column>
      <el-table-column prop="position" label="职位" header-align="center" align="center"></el-table-column>
      <el-table-column prop="address" label="地址" header-align="center" align="center" width="100"></el-table-column>
      <el-table-column prop="email" label="邮箱" header-align="center" align="center" width="150"></el-table-column>
      <el-table-column prop="wechat" label="微信" header-align="center" align="center" width="150"></el-table-column>
      <el-table-column prop="website" label="网站" header-align="center" align="center" width="150"></el-table-column>
      <el-table-column prop="category" label="类别" header-align="center" align="center"></el-table-column>
      <el-table-column prop="industry" label="行业" header-align="center" align="center"></el-table-column>
      <el-table-column prop="comTradeKey1" label="标签1" header-align="center" align="center"></el-table-column>
      <el-table-column prop="contactTag" label="联络标签" header-align="center" align="center" width="100" ></el-table-column>
      <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
      <el-table-column prop="source" label="来源" header-align="center" align="center"></el-table-column>
      <el-table-column prop="state" label="状态" header-align="center" align="center"></el-table-column>
      <el-table-column prop="createTime" label="创建时间" header-align="center" align="center" width="120"></el-table-column>
      <el-table-column prop="updateTime" label="更新时间" header-align="center" align="center" width="120"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('crm:crmperson:update')" type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="state.hasPermission('crm:crmperson:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./crmperson-add-or-update.vue";

const view = reactive({
  getDataListURL: "/crm/crmperson/page",
  getDataListIsPage: true,
  exportURL: "/crm/crmperson/export",
  deleteURL: "/crm/crmperson",
  deleteIsBatch: true,
  dataForm: {
    id: "",
    name: "",
    company: "",
    mobile: "",
    address: "",
    category: "",
    source: "",
    state: "",
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });


const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(id);
  });
};
</script>